home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cxl52_1.zip / CXLDEMO.C < prev    next >
C/C++ Source or Header  |  1990-02-17  |  47KB  |  1,448 lines

  1. /* ┌┬───────────────────────────────────────────────────────────────────┬┐
  2.    ││                                                                   ││
  3.    ││                     CXL Demonstration Program                     ││
  4.    ││                                                                   ││
  5.    ││              CXL is Copyright (c) 1987-1990 by Mike Smedley       ││
  6.    ││                                                                   ││
  7.    ││               Syntax:  CXLDEMO [-switches]                        ││
  8.    ││                                                                   ││
  9.    ││                        -c = CGA snow elimination                  ││
  10.    ││                        -b = BIOS screen writing                   ││
  11.    ││                        -m = force monochrome text attributes      ││
  12.    ││                                                                   ││
  13.    ││               Compiler command lines:                             ││
  14.    ││                                                                   ││
  15.    ││                MSC:    cl -Ox cxldemo.c cxlmss.lib                ││
  16.    ││                QC:     qcl -Ox cxldemo.c cxlmss.lib               ││
  17.    ││                TC:     tcc -Z -O cxldemo.c cxltcs.lib             ││
  18.    ││                ZTC:    ztc -msi -o -b cxldemo.c cxlzts.lib        ││
  19.    ││                                                                   ││
  20.    └┴───────────────────────────────────────────────────────────────────┴┘ */
  21.  
  22. /*---------------------------------------------------------------------------*/
  23.  
  24. /* header files */
  25. #include <conio.h>
  26. #include <ctype.h>
  27. #include <dos.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include "cxldef.h"
  32. #include "cxlkey.h"
  33. #include "cxlmou.h"
  34. #include "cxlstr.h"
  35. #include "cxlvid.h"
  36. #include "cxlwin.h"
  37.  
  38. #if defined(__TURBOC__)                             /* Turbo C */
  39.     #include <dir.h>
  40. #else
  41.     #include <direct.h>                             /* all others */
  42. #endif
  43.  
  44. #if defined(M_I86) && !defined(__ZTC__)             /* MSC/QuickC */
  45.     #define bioskey(a)       _bios_keybrd(a)
  46.     #define findfirst(a,b,c) _dos_findfirst(a,c,b)
  47.     #define findnext(a)      _dos_findnext(a)
  48.     #define ffblk            find_t
  49.     #define ff_name          name
  50. #elif defined(__ZTC__)                              /* Zortech C/C++ */
  51.     #define ffblk             FIND
  52.     #define ff_name           name
  53.     #define ff_attrib         attribute
  54. #endif
  55.  
  56. /*---------------------------------------------------------------------------*/
  57.  
  58. /* function prototypes */
  59. static void activate_demo (void);
  60. static void add_shadow    (void);
  61. static void chg_attr_demo (void);
  62. static void chg_bord_demo (void);
  63. static void chg_wind_attr (int battr,int wattr);
  64. static int  check_date    (char *buf);
  65. static void close_windows (void);
  66. static void confirm_quit  (void);
  67. static void copy_demo     (void);
  68. static void cxlinfo       (void);
  69. static void datademo      (void);
  70. static void directory     (void);
  71. static void display_date  (void);
  72. static void disp_sure_msg (void);
  73. static void display_title (int tpos);
  74. static void do_nothing    (void);
  75. static void error_exit    (int errnum);
  76. static void execute       (void);
  77. static int  find_first    (char *filespec,struct ffblk *ffblk);
  78. static int  find_next     (struct ffblk *ffblk);
  79. static unsigned get_key   (int *done);
  80. static void hide_demo     (void);
  81. static void horz_line     (int wrow,int wcol,int count,int attr);
  82. static void initialize    (void);
  83. static void line_inp_demo (void);
  84. static void main_menu     (void);
  85. static void menudemo      (void);
  86. static void move_bar_down (void);
  87. static void move_demo     (void);
  88. static void move_window   (int nsrow,int nscol);
  89. static void normal_exit   (void);
  90. static void open_back_wind(void);
  91. static void open_stat_wind(void);
  92. static void open_titl_wind(void);
  93. static void os_shell      (void);
  94. static void parse_cmd_line(int argc,char *argv[]);
  95. static void parse_date    (char *buf,int *month,int *day,int *year);
  96. static void pick_compiler (void);
  97. static void pickdemo      (void);
  98. static void popup_demo    (void);
  99. static void pre_help      (void);
  100. static void pre_menu1     (void);
  101. static void pre_menu2     (void);
  102. static void pre_pick1     (void);
  103. static void press_a_key   (int wrow);
  104. static void pulldown_demo (void);
  105. static void quit_window   (void);
  106. static void resize_demo   (void);
  107. static void restore_cursor(void);
  108. static void r_margin      (void);
  109. static void scroll_demo   (void);
  110. static void setup_menu    (void);
  111. static void short_delay   (void);
  112. static void size_window   (int nerow,int necol);
  113. static void text_line_demo(void);
  114. static void title_demo    (void);
  115. static void toggle_block  (void);
  116. static void toggle_yn     (void);
  117. static void update_clock  (void);
  118. static void vert_line     (int wrow,int wcol,int count,int attr);
  119. static void you_selected  (char *str);
  120. static void windemo       (void);
  121.  
  122. /*---------------------------------------------------------------------------*/
  123.  
  124. /* miscellaneous global variables */
  125. static int *savescrn,crow,ccol;
  126. static WINDOW w[10];
  127.  
  128. /*---------------------------------------------------------------------------*/
  129.  
  130. /* fields used in data entry demo */
  131. static char date[7],firstname[16],initial[2],lastname[26],address[41],city[21],
  132.             state[3],zipcode[10],phone[11],compiler[16],amtenc[8],comments[41],
  133.             ssan[10];
  134.  
  135. /*---------------------------------------------------------------------------*/
  136.  
  137. /* months table */
  138. static char *months[]= {
  139.     "January","February","March","April","May","June","July","August",
  140.     "September","October","November","December",NULL
  141. };
  142.  
  143. /* printer ports table */
  144. static char *prn_ports[]= { "PRN","LPT1","LPT2","COM1","COM2",NULL };
  145.  
  146. /* error message table */
  147. static char *error_text[]= {
  148.     NULL,   /* errnum =  0, no error        */
  149.     NULL,   /* errnum == 1, windowing error */
  150.     "Syntax:  CXLDEMO [-switches]\n\n"
  151.         "\t -c = CGA snow elimination\n"
  152.         "\t -b = BIOS screen writing\n"
  153.         "\t -m = force monochrome text attributes",
  154.     "Memory allocation error"
  155. };
  156.  
  157. /* compiler table */
  158. static char *compilers[]=
  159.     { "Microsoft C","Quick C","Turbo C","Zortech C/C++" };
  160.  
  161. /*---------------------------------------------------------------------------*/
  162.  
  163. /* help category numbers */
  164. #define H_GLOBAL    1
  165. #define H_WINDOWING 2
  166. #define H_MENUING   3
  167. #define H_LISTPICK  4
  168. #define H_STRPICK   5
  169. #define H_FILEPICK  6
  170. #define H_DATAENTRY 7
  171. #define H_EDITKEYS  8
  172. #define H_DATE      9
  173. #define H_FIRSTNAME 10
  174. #define H_INITIAL   11
  175. #define H_LASTNAME  12
  176. #define H_CITY      13
  177. #define H_STATE     14
  178. #define H_ZIPCODE   15
  179. #define H_COMPILER  16
  180. #define H_AMOUNT    17
  181. #define H_NUMERIC   18
  182. #define H_PULLDOWN  19
  183. #define H_FILE      20
  184. #define H_EDITING   21
  185. #define H_LOAD      22
  186. #define H_SAVE      23
  187. #define H_RENAME    24
  188. #define H_NEW       25
  189. #define H_DIRECTORY 26
  190. #define H_EXECUTE   27
  191. #define H_OSSHELL   28
  192. #define H_QUIT      29
  193. #define H_SCROLL    30
  194. #define H_CHGATTR   31
  195. #define H_CHGBORD   32
  196. #define H_WINTITLE  33
  197. #define H_RESIZE    34
  198. #define H_TEXTLINE  35
  199. #define H_WINMOVE   36
  200. #define H_WINHIDE   37
  201. #define H_ACTIVATE  38
  202. #define H_WINCOPY   39
  203.  
  204. /*---------------------------------------------------------------------------*/
  205.  
  206. /* miscellaneous defines */
  207. #define SHORT_DELAY 11
  208.  
  209. /*---------------------------------------------------------------------------*/
  210.  
  211. void main(int argc,char *argv[])
  212. {
  213.     initialize();
  214.     parse_cmd_line(argc,argv);
  215.     open_back_wind();
  216.     open_stat_wind();
  217.     open_titl_wind();
  218.     main_menu();
  219.     normal_exit();
  220. }
  221.  
  222. /*---------------------------------------------------------------------------*/
  223.  
  224. static void activate_demo(void)
  225. {
  226.     register int i;
  227.  
  228.     if((w[5]=wopen(9,44,22,78,1,LCYAN|_CYAN,WHITE|_CYAN))==0) error_exit(1);
  229.     whelpcat(H_ACTIVATE);
  230.     wputs("\n  CXL's wactiv() is used to"
  231.           "\n  activate a window, making"
  232.           "\n  it available for windowing"
  233.           "\n  operations.");
  234.     press_a_key(6);
  235.  
  236.     /* activate windows 0 thru 5 in order, back to front */
  237.     for(i=0;i<6;i++) {
  238.         wactiv(w[i]);
  239.         short_delay();
  240.     }
  241. }
  242.  
  243. /*---------------------------------------------------------------------------*/
  244.  
  245. /* this function will add a shadow to the active window */
  246.  
  247. static void add_shadow(void)
  248. {
  249.     wshadow(LGREY|_BLACK);
  250. }
  251.  
  252. /*---------------------------------------------------------------------------*/
  253.  
  254. static void chg_attr_demo(void)
  255. {
  256.     if((w[1]=wopen(9,35,22,65,0,YELLOW|_BLUE,LCYAN|_BLUE))==0) error_exit(1);
  257.     whelpcat(H_CHGATTR);
  258.     wputs("\n  The wchgattr() function"
  259.           "\n  allows you to change the"
  260.           "\n  attribute of the active"
  261.           "\n  window.");
  262.     press_a_key(6);
  263.     chg_wind_attr(LMAGENTA|_BLUE ,WHITE|_GREEN);
  264.     chg_wind_attr(LGREEN|_LGREY  ,LMAGENTA|_RED);
  265.     chg_wind_attr(YELLOW|_BROWN  ,LCYAN|_BLUE);
  266.     chg_wind_attr(YELLOW|_MAGENTA,YELLOW|_MAGENTA);
  267.     chg_wind_attr(LRED|_MAGENTA  ,WHITE|_MAGENTA);
  268. }
  269.  
  270. /*---------------------------------------------------------------------------*/
  271.  
  272. static void chg_bord_demo(void)
  273. {
  274.     register int i;
  275.  
  276.     whelpcat(H_CHGBORD);
  277.     wtextattr(LGREEN|_MAGENTA);
  278.     wputs("\n\n  The wborder() function is"
  279.             "\n  used to change the style"
  280.             "\n  of the window's border.");
  281.     press_a_key(10);
  282.     for(i=5;i>=0;i--) {
  283.         wborder(i);
  284.         short_delay();
  285.     }
  286. }
  287.  
  288. /*---------------------------------------------------------------------------*/
  289.  
  290. static void chg_wind_attr(int battr,int wattr)
  291. {
  292.     wchgattr(battr,wattr);
  293.     short_delay();
  294. }
  295.  
  296. /*---------------------------------------------------------------------------*/
  297.  
  298. /* this function validates the Date field in the data entry window */
  299.  
  300. static int check_date(char *buf)
  301. {
  302.     int year,month,day;
  303.  
  304.     if(!strblank(buf)) {
  305.         parse_date(buf,&month,&day,&year);
  306.  
  307.         /* validate numeric values */
  308.         if(month<1 || month>12) {
  309.             wperror("Invalid month");
  310.             return(1);
  311.         }
  312.         if(day<1 || day>31) {
  313.             wperror("Invalid day");
  314.             return(3);
  315.         }
  316.     }
  317.  
  318.     /* return normally */
  319.     return(0);
  320. }
  321.  
  322. /*---------------------------------------------------------------------------*/
  323.  
  324. static void close_windows(void)
  325. {
  326.     register int i;
  327.  
  328.     for(i=0;i<8;i++) {
  329.         wclose();
  330.         short_delay();
  331.     }
  332. }
  333.  
  334. /*---------------------------------------------------------------------------*/
  335.  
  336. /* this function pops open a window and confirms that the user really */
  337. /* wants to quit the demo.  If so, it terminates the demo program.    */
  338.  
  339. static void confirm_quit(void)
  340. {
  341.     struct _onkey_t *kblist;
  342.  
  343.     kblist=chgonkey(NULL);  /* hide any existing hot keys */
  344.     if(_mouse&MS_CURS) mshidecur();
  345.     if(!wopen(9,26,13,55,0,WHITE|_BROWN,WHITE|_BROWN)) error_exit(1);
  346.     add_shadow();
  347.     wputs("\n Quit demo, are you sure? \033A\156Y\b");
  348.     clearkeys();
  349.     showcur();
  350.     if(wgetchf("YN",'Y')=='Y') normal_exit();
  351.     wclose();
  352.     hidecur();
  353.     if(_mouse&MS_CURS) msshowcur();
  354.     chgonkey(kblist);       /* restore any hidden hot keys */
  355. }
  356.  
  357. /*---------------------------------------------------------------------------*/
  358.  
  359. static void copy_demo(void)
  360. {
  361.     whelpcat(H_WINCOPY);
  362.     wtextattr(LCYAN|_CYAN);
  363.     wputs("\n\n  The wcopy() function is used"
  364.             "\n  to copy the active window.");
  365.     press_a_key(9);
  366.     if(!wcopy(1,1)) error_exit(1);
  367.     short_delay();
  368.     if(!wcopy(3,40)) error_exit(1);
  369.     short_delay();
  370.     short_delay();
  371. }
  372.  
  373. /*---------------------------------------------------------------------------*/
  374.  
  375. static void cxlinfo(void)
  376. {
  377.     if(!wopen(4,6,20,72,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  378.     add_shadow();
  379.     wcenters(1,LCYAN|_RED,"CXL Version 5.2");
  380.     wcenters(2,LCYAN|_RED,"Written by Mike Smedley");
  381.     wcenters(3,LCYAN|_RED,"Copyright (c) 1987-1990  All Rights Reserved");
  382.     wgotoxy(5,0);
  383.     wputs("    CXL is a User-Supported C function library  that supports\n"
  384.           "    Microsoft C, QuickC, Turbo C, and Zortech C/C++.  There  \n"
  385.           "    are  over 260  functions  available for  your  use.      \n"
  386.           "    When  you  register you  get  the remaining memory models\n"
  387.           "    supported by  your  compiler  and the  full  source code!\n"
  388.           "    CXL's  routines  are  written  in  99%   well-documented,\n"
  389.           "    easy-to-modify  C code.  See  documentation  for details.\n\n");
  390.     press_a_key(13);
  391.     wclose();
  392.     move_bar_down();
  393. }
  394.  
  395. /*---------------------------------------------------------------------------*/
  396.  
  397. static void datademo(void)
  398. {
  399.     register int ch,mode=0;
  400.     unsigned key;
  401.  
  402.     if(!wopen(2,8,20,70,1,LCYAN|_BLUE,LCYAN|_BLUE)) error_exit(1);
  403.     add_shadow();
  404.     wtitle("[ CXL Order Form ]",TLEFT,LCYAN|_BLUE);
  405.     wmessage(" [F10]=Finished ",BT_BORD, 5,LCYAN|_BLUE);
  406.     wmessage(" [Esc]=Abort "   ,BT_BORD,45,LCYAN|_BLUE);
  407.     whelpushc(H_EDITKEYS);
  408.     do {
  409.  
  410.         /* Mark beginning of form. */
  411.         winpbeg(LGREEN|_LGREY,WHITE|_LGREY);
  412.  
  413.         /* Display prompts and define fields. */
  414.         wprints( 1, 3,WHITE|_BLUE,"Date");
  415.         winpdef( 1,16,date,"<01>#'/'<0123>#'/'<89>#",0,mode,check_date,H_DATE);
  416.         winpfba(NULL,display_date);
  417.         wprints( 3, 3,WHITE|_BLUE,"First Name");
  418.         winpdef(3,16,firstname,"MMMMMMMMMMMMMMM",0,mode,NULL,H_FIRSTNAME);
  419.         wprints( 3,37,WHITE|_BLUE,"Initial");
  420.         winpdef( 3,47,initial,"U'.'",0,mode,NULL,H_INITIAL);
  421.         wprints( 5, 3,WHITE|_BLUE,"Last Name");
  422.         winpdef( 5,16,lastname,"MMMMMMMMMMMMMMMMMMMMMMMMM",0,mode,NULL
  423.             ,H_LASTNAME);
  424.         wprints( 7, 3,WHITE|_BLUE,"Address");
  425.         winpdef( 7,16,address,"****************************************",'M'
  426.             ,mode,NULL,0);
  427.         wprints( 9, 3,WHITE|_BLUE,"City");
  428.         winpdef( 9,16,city,"MMMMMMMMMMMMMMMMMMMM",0,mode,NULL,H_CITY);
  429.         wprints( 9,41,WHITE|_BLUE,"State");
  430.         winpdef( 9,50,state,"UU",0,mode,NULL,H_STATE);
  431.         wprints(11, 3,WHITE|_BLUE,"Zip Code");
  432.         winpdef(11,16,zipcode,"#####'-'%%%%",0,mode,NULL,H_ZIPCODE);
  433.         wprints(11,31,WHITE|_BLUE,"Phone");
  434.         winpdef(11,40,phone,"'('###') '###'-'####",0,mode,NULL,0);
  435.         wprints(13, 3,WHITE|_BLUE,"Compiler");
  436.         winpdef(13,16,compiler,"***************",'M',mode,NULL,H_COMPILER);
  437.         winpfba(pick_compiler,NULL);
  438.         wprints(13,37,WHITE|_BLUE,"Amount");
  439.         winpdef(13,46,amtenc,"'$'99999.99",'9',mode,NULL,H_AMOUNT);
  440.         wprints(15, 3,WHITE|_BLUE,"Comments");
  441.         winpdef(15,16,comments,"****************************************",0
  442.             ,mode,NULL,0);
  443.  
  444.         /* Define alternate keyboard get function. */
  445.         winpkey(get_key,&key);
  446.  
  447.         /* Mark end of form and process it.  If [Esc] was pressed, */
  448.         /* then don't bother with the confirmation message.        */
  449.         if(winpread()) break;
  450.  
  451.         /* Test to see if [F10] was pressed.  If   */
  452.         /* so, don't display confirmation message. */
  453.         if(key==0x4400) break;
  454.  
  455.         /* Display confirmation message. */
  456.         if(!wopen(9,24,13,57,0,WHITE|_CYAN,WHITE|_CYAN)) error_exit(1);
  457.         add_shadow();
  458.         wputs("\n Is this information correct? \033A\076Y\b");
  459.         clearkeys();
  460.         ch=wgetchf("YN",'Y');
  461.         wclose();
  462.  
  463.         /* Change field mode to "update". */
  464.         mode=1;
  465.  
  466.     } while(ch!='Y');
  467.     whelpopc();
  468.     line_inp_demo();
  469.     wclose();
  470.     hidecur();
  471.     move_bar_down();
  472. }
  473.  
  474. /*---------------------------------------------------------------------------*/
  475.  
  476. /* this function displays a quick 'n' dirty directory of current path */
  477.  
  478. static void directory(void)
  479. {
  480.     static int busy=NO;
  481.     char filespec[41],file1[13],file2[13];
  482.     int i,done,lines,files;
  483.     struct ffblk ffblk;
  484.  
  485.     if(busy) return; else busy=YES;     /* avoid recursion */
  486.     strcpy(filespec,"*.*");
  487.     if(_mouse) mshidecur();
  488.     showcur();
  489.     if(!wopen(4,14,20,59,0,LRED|_MAGENTA,LCYAN|_BLUE)) error_exit(1);
  490.     wtitle("[ Directory ]",TCENTER,LRED|_MAGENTA);
  491.     if(!wopen(6,6,8,49,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  492.     wtitle("[ Filespec ]",TCENTER,LMAGENTA|_RED);
  493.     winpbeg(BLUE|_LGREY,BLUE|_LGREY);
  494.     winpdef(0,1,filespec,"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",'U',2
  495.         ,NULL,H_EDITKEYS);
  496.     i=winpread();
  497.     wclose();
  498.     if(!i) {
  499.         wclear();
  500.         wtextattr(LCYAN|_BLUE);
  501.         lines=files=0;
  502.         done=find_first(filespec,&ffblk);
  503.         for(;;) {
  504.             if(done) break;
  505.             files++;
  506.             strcpy(file1,ffblk.ff_name);
  507.             if(!done) done=find_next(&ffblk);
  508.             strcpy(file2,ffblk.ff_name);
  509.             if(done)
  510.                 file2[0]='\0';
  511.             else {
  512.                 files++;
  513.                 done=find_next(&ffblk);
  514.             }
  515.             if(done)
  516.                 ffblk.ff_name[0]='\0';
  517.             else
  518.                 files++;
  519.             wprintf(" %-15s%-15s%s\n",file1,file2,ffblk.ff_name);
  520.             lines++;
  521.             if(lines>=14) {
  522.                 wtextattr(LGREEN|_BLUE);
  523.                 wprintf(" Press a key to continue....");
  524.                 wtextattr(LCYAN|_BLUE);
  525.                 i=waitkey();
  526.                 wprintf("\r");
  527.                 if(i==ESC) break;
  528.                 lines=0;
  529.             }
  530.             if(!done) done=find_next(&ffblk);
  531.         }
  532.         wtextattr(LGREEN|_BLUE);
  533.         wprintf(" Files found:  %d  Press a key....",files);
  534.         waitkey();
  535.     }
  536.     hidecur();
  537.     wclose();
  538.     if(_mouse) msshowcur();
  539.     busy=NO;
  540. }
  541.  
  542. /*---------------------------------------------------------------------------*/
  543.  
  544. /* this function displays the literal equivalent of the MMDDYY */
  545. /* date that the user entered into the Date field.  It is      */
  546. /* called immediately after the user leaves the Date field.    */
  547.  
  548. static void display_date(void)
  549. {
  550.     struct _field_t *field;
  551.     int month,day,year;
  552.  
  553.     /* find address of Date field's record */
  554.     if((field=winpffind(1,16))==NULL) error_exit(1);
  555.  
  556.     /* set cursor and clear to end of window's line */
  557.     hidecur();
  558.     wgotoxy(1,37);
  559.     wclreol();
  560.  
  561.     /* don't display date string if Date field is empty */
  562.     if(!strblank(field->buf)) {
  563.  
  564.         /* parse string date into numeric values */
  565.         parse_date(field->buf,&month,&day,&year);
  566.  
  567.         /* display date */
  568.         wprintf("%s %d, %d",months[month-1],day,year);
  569.     }
  570.     showcur();
  571. }
  572.  
  573. /*---------------------------------------------------------------------------*/
  574.  
  575. /* this function is called by the pull-down demo for a prompt */
  576.  
  577. static void disp_sure_msg(void)
  578. {
  579.     wprints(0,2,WHITE|_BLUE,"Are you sure?");
  580. }
  581.  
  582. /*---------------------------------------------------------------------------*/
  583.  
  584. static void display_title(int tpos)
  585. {
  586.     wtitle("[ My Title ]",tpos,LCYAN|_GREEN);
  587.     short_delay();
  588. }
  589.  
  590. /*---------------------------------------------------------------------------*/
  591.  
  592. /* this function is used as a dummy function for */
  593. /* several menu items in the pull-down demo      */
  594.  
  595. static void do_nothing(void)
  596. {
  597. }
  598.  
  599. /*---------------------------------------------------------------------------*/
  600.  
  601. /* this function handles abnormal termination.  If it is passed an  */
  602. /* error code of 1, then it is a windowing system error.  Otherwise */
  603. /* the error message is looked up in the error message table.       */
  604.  
  605. static void error_exit(int errnum)
  606. {
  607.     if(errnum) {
  608.         printf("\n%s\n",(errnum==1)?werrmsg():error_text[errnum]);
  609.     exit(errnum);
  610.     }
  611. }
  612.  
  613. /*---------------------------------------------------------------------------*/
  614.  
  615. /* this function is used by the pull-down demo. */
  616. /* It is used to execute a DOS command.         */
  617.  
  618. static void execute(void)
  619. {
  620.     static int busy=NO;
  621.     char command[61];
  622.     int *scrn;
  623.  
  624.     if(busy) return; else busy=YES;     /* avoid recursion */
  625.     showcur();
  626.     if(_mouse) mshidecur();
  627.     if(!wopen(8,7,10,70,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  628.     wtitle("[ Execute DOS Command ]",TCENTER,LMAGENTA|_RED);
  629.     winpbeg(BLUE|_LGREY,BLUE|_LGREY);
  630.     winpdef(0,1,command,"****************************************"
  631.         "********************",0,0,NULL,H_EDITKEYS);
  632.     if(!winpread()) {
  633.         if((scrn=ssave())==NULL) error_exit(3);
  634.         cclrscrn(LGREY|_BLACK);
  635.         system(command);
  636.         printf("\nPress any key to continue....");
  637.         waitkey();
  638.         srestore(scrn);
  639.     }
  640.     hidecur();
  641.     if(_mouse) msshowcur();
  642.     wclose();
  643.     busy=NO;
  644. }
  645.  
  646. /*---------------------------------------------------------------------------*/
  647.  
  648. static int find_first(char *filespec,struct ffblk *ffblk)
  649. {
  650.     register int done;
  651.  
  652. #if defined(__ZTC__)
  653.     struct ffblk *pffblk;
  654.     if((pffblk=findfirst(filespec,0))==NULL)
  655.         done=YES;
  656.     else {
  657.         *ffblk=*pffblk;
  658.         done=NO;
  659.     }
  660. #else
  661.     done=findfirst(filespec,ffblk,0);
  662. #endif
  663.     return(done);
  664. }
  665.  
  666. /*---------------------------------------------------------------------------*/
  667.  
  668. static int find_next(struct ffblk *ffblk)
  669. {
  670.     register int done;
  671.  
  672. #if defined(__ZTC__)
  673.     struct ffblk *pffblk;
  674.     pffblk=findnext();
  675.     if(pffblk==NULL)
  676.         done=YES;
  677.     else {
  678.         done=NO;
  679.         *ffblk=*pffblk;
  680.     }
  681. #else
  682.     done=findnext(ffblk);
  683. #endif
  684.     return(done);
  685. }
  686.  
  687. /*---------------------------------------------------------------------------*/
  688.  
  689. /* This function serves as an alternate get key function for the */
  690. /* data entry demo.  In this example, I do a normal keyboard     */
  691. /* get, but if the key is [F10], I want to exit the form.  The   */
  692. /* purpose of this is to demonstrate how to extend winpread().   */
  693.  
  694. unsigned get_key(int *done)
  695. {
  696.     unsigned int xch;
  697.  
  698.     xch=getxch();
  699.     *done=(xch==0x4400);    /* [F10] */
  700.     return(xch);
  701. }
  702.  
  703. /*---------------------------------------------------------------------------*/
  704.  
  705. static void hide_demo(void)
  706. {
  707.     register int i;
  708.  
  709.     whelpcat(H_WINHIDE);
  710.     wtextattr(LCYAN|_BROWN);
  711.     wputs("\n\n   The whide() and wunhide()"
  712.             "\n   functions are used to hide"
  713.             "\n   and unhide windows.");
  714.     press_a_key(9);
  715.  
  716.     /* hide all windows, front to back */
  717.     for(i=0;i<5;i++) {
  718.         if(whide()) error_exit(1);
  719.         short_delay();
  720.     }
  721.  
  722.     /* unhide most recently hidden first */
  723.     for(i=0;i<5;i++) {
  724.         if(wunhide(0)) error_exit(1);
  725.         short_delay();
  726.     }
  727. }
  728.  
  729. /*---------------------------------------------------------------------------*/
  730.  
  731. static void horz_line(int wrow,int wcol,int count,int attr)
  732. {
  733.     whline(wrow,wcol,count,3,attr);
  734.     short_delay();
  735. }
  736.  
  737. /*---------------------------------------------------------------------------*/
  738.  
  739. /* this function initializes CXL's video, mouse, keyboard, and help systems */
  740.  
  741. static void initialize(void)
  742. {
  743.     /* initialize the CXL video system and save current screen info */
  744.     videoinit();
  745.     readcur(&crow,&ccol);
  746.     if((savescrn=ssave())==NULL) error_exit(3);
  747.  
  748.     /* if mouse exists, turn on full mouse support */
  749.     if(msinit()) {
  750.         mssupport(MS_FULL);
  751.         msgotoxy(12,49);
  752.     }
  753.  
  754.     /* attach [Alt-X] to the confirm_quit() function */
  755.     setonkey(0x2d00,confirm_quit,0);
  756.  
  757.     /* initialize help system, help key = [F1] */
  758.     whelpdef("CXLDEMO.HLP",0x3b00,YELLOW|_RED,LRED|_RED,WHITE|_RED,RED|_LGREY
  759.         ,pre_help);
  760. }
  761.  
  762. /*---------------------------------------------------------------------------*/
  763.  
  764. static void line_inp_demo(void)
  765. {
  766.     if(!wopen(5,21,15,58,3,LGREEN|_MAGENTA,LGREEN|_MAGENTA)) error_exit(1);
  767.     wtitle("[ Single-Line Input ]",TCENTER,LGREEN|_MAGENTA);
  768.     whelpcat(H_DATAENTRY);
  769.     add_shadow();
  770.     restore_cursor();
  771.     if(winputsf(phone,"'\n\n  Phone Number?    '!R--!"
  772.         "'('!+!###!-!') '!+!###!-!'-'!+!####")) confirm_quit();
  773.     restore_cursor();
  774.     if(winputsf(ssan,"'\n\n  Soc Sec Number?  '!R-!"
  775.         "<01234567>##!-!'-'!+!##!-!'-'!+!####")) confirm_quit();
  776.     restore_cursor();
  777.     if(winputsf(date,"\"\n\n  Today's Date?    \"!R-!"
  778.         "<01>#!-!'/'!+!<0123>#!-!'/'!+!'19'<89>#")) confirm_quit();
  779.     wclose();
  780. }
  781.  
  782. /*---------------------------------------------------------------------------*/
  783.  
  784. static void main_menu(void)
  785. {
  786.     /* push global help category onto help stack, so when   */
  787.     /* [F1] is pressed while selection bar is on an item    */
  788.     /* without help, the global help category will be used. */
  789.     whelpushc(H_GLOBAL);
  790.  
  791.     /* define and process the main menu */
  792.     wmenubeg(9,27,16,53,0,LBLUE|_BLUE,LBLUE|_BLUE,pre_menu1);
  793.     wmenuitem(0,0,"Windowing"   ,'W',1,0,windemo ,0,H_WINDOWING);
  794.     wmenuitem(1,0,"Menuing"     ,'M',2,0,menudemo,0,H_MENUING);
  795.     wmenuitem(2,0,"List picking",'L',3,0,pickdemo,0,H_LISTPICK);
  796.     wmenuitem(3,0,"Data entry"  ,'D',4,0,datademo,0,H_DATAENTRY);
  797.     wmenuitem(4,0,"Information" ,'I',5,0,cxlinfo ,0,0);
  798.     wmenuitem(5,0,"Exit demo"   ,'E',6,0,NULL    ,0,0);
  799.     wmenuend(1,M_VERT,25,6,LCYAN|_BLUE,WHITE|_BLUE,0,BLUE|_LGREY);
  800.     if(wmenuget()==-1) if(_winfo.errno>W_ESCPRESS) error_exit(1);
  801.  
  802.     /* pop the global help category off of the stack, and into the void */
  803.     whelpopc();
  804. }
  805.  
  806. /*---------------------------------------------------------------------------*/
  807.  
  808. static void menudemo(void)
  809. {
  810.     pulldown_demo();
  811.     move_bar_down();
  812. }
  813.  
  814. /*---------------------------------------------------------------------------*/
  815.  
  816. /* This function is used to move the selection bar of the Main Menu  */
  817. /* down to the next menu item.  It does this by fetching the address */
  818. /* of the current menu, then setting the current tagid to the tagid  */
  819. /* of the next menu item.  If I had not numbered the menu items'     */
  820. /* tagids sequentially, this would not work.                         */
  821.  
  822. static void move_bar_down(void)
  823. {
  824.     wmenuinext(wmenuicurr()->tagid+1);
  825. }
  826.  
  827. /*---------------------------------------------------------------------------*/
  828.  
  829. static void move_demo(void)
  830. {
  831.     if((w[4]=wopen(4,2,16,35,2,LGREEN|_BROWN,WHITE|_BROWN))==0) error_exit(1);
  832.     whelpcat(H_WINMOVE);
  833.     wputs("\n   To move the active window,"
  834.           "\n   the wmove() function is"
  835.           "\n   used.");
  836.     press_a_key(5);
  837.     move_window(0,0);
  838.     move_window(10,4);
  839.     move_window(6,19);
  840.     move_window(1,13);
  841.     move_window(11,35);
  842.     move_window(2,39);
  843. }
  844.  
  845. /*---------------------------------------------------------------------------*/
  846.  
  847. static void move_window(int nsrow,int nscol)
  848. {
  849.     if(wmove(nsrow,nscol)) error_exit(1);
  850.     short_delay();
  851. }
  852.  
  853. /*---------------------------------------------------------------------------*/
  854.  
  855. /* this function handles normal termination.  The original screen and cursor */
  856. /* coordinates are restored before exiting to DOS with ERRORLEVEL 0.         */
  857.  
  858. static void normal_exit(void)
  859. {
  860.     srestore(savescrn);
  861.     gotoxy_(crow,ccol);
  862.     if(_mouse) mshidecur();
  863.     showcur();
  864.     exit(0);
  865. }
  866.  
  867. /*---------------------------------------------------------------------------*/
  868.  
  869. static void open_back_wind(void)
  870. {
  871.     register int i;
  872.  
  873.     if(!wopen(0,0,23,79,5,0,LGREEN|_GREEN)) error_exit(1);
  874.     for(i=1;i<320;i++) wprintf("\033F%cCXL   ",i);
  875. }
  876.  
  877. /*---------------------------------------------------------------------------*/
  878.  
  879. static void open_stat_wind(void)
  880. {
  881.     wfillch('\260');
  882.     wopen(24,0,24,79,5,0,LGREY|_RED);
  883.     wprints( 0, 1,LGREY|_RED,"[F1]=Help");
  884.     wcenters(0   ,LGREY|_RED,"Select demonstration to view.");
  885.     wrjusts( 0,78,LGREY|_RED,"[Alt-X]=Quit");
  886.     wfillch(' ');
  887. }
  888.  
  889. /*---------------------------------------------------------------------------*/
  890.  
  891. static void open_titl_wind(void)
  892. {
  893.     if(!wopen(1,12,5,67,0,LRED|_MAGENTA,LRED|_MAGENTA)) error_exit(1);
  894.     add_shadow();
  895.     wcenters(0,WHITE|_MAGENTA,"Welcome to the CXL Demonstration Program!");
  896.     wcenters(2,LCYAN|_MAGENTA,"CXL is Copyright (c) 1987-1990 by Mike Smedley");
  897. }
  898.  
  899. /*---------------------------------------------------------------------------*/
  900.  
  901. /* this is used by the pull-down demo.  It is the */
  902. /* [O]S Shell function under the [F]ile menu      */
  903.  
  904. static void os_shell(void)
  905. {
  906.     int *scrn;
  907.  
  908.     showcur();
  909.     if(_mouse) mshidecur();
  910.     if((scrn=ssave())==NULL) error_exit(3);
  911.     cclrscrn(LGREY|_BLACK);
  912.     printf("Type EXIT to return....\n");
  913.     system("COMMAND");
  914.     srestore(scrn);
  915.     hidecur();
  916.     if(_mouse) msshowcur();
  917. }
  918.  
  919. /*---------------------------------------------------------------------------*/
  920.  
  921. /* this function parses the command line for valid invocation switches.  If  */
  922. /* any valid switches are found, the appropriate video variable will be      */
  923. /* set.  If any invalid parameters are found, a syntax message is displayed. */
  924.  
  925. static void parse_cmd_line(int argc,char *argv[])
  926. {
  927.     register int i,j;
  928.     char *p;
  929.  
  930.     for(i=1;i<argc;i++) {
  931.         p=argv[i];
  932.         if(*p=='-'||*p=='/') {
  933.             for(j=1;*(p+j);j++) {
  934.                 switch(tolower(*(p+j))) {
  935.                     case 'c':
  936.                         setvparam(VP_CGA);
  937.                         break;
  938.                     case 'b':
  939.                         setvparam(VP_BIOS);
  940.                         break;
  941.                     case 'm':
  942.                         setvparam(VP_MONO);
  943.                         break;
  944.                     default:
  945.                         error_exit(2);
  946.                 }
  947.             }
  948.         }
  949.         else
  950.             error_exit(2);
  951.     }
  952. }
  953.  
  954. /*---------------------------------------------------------------------------*/
  955.  
  956. /* this function parses a MMDDYY date string into separate numeric values */
  957.  
  958. static void parse_date(char *buf,int *month,int *day,int *year)
  959. {
  960.     char date[7];
  961.  
  962.     strcpy(date,buf);
  963.     *year=1900+atoi(date+4);
  964.     *(date+4)='\0';
  965.     *day=atoi(date+2);
  966.     *(date+2)='\0';
  967.     *month=atoi(date);
  968. }
  969.  
  970. /*---------------------------------------------------------------------------*/
  971.  
  972. static void pick_compiler(void)
  973. {
  974.     register int subscr,i;
  975.  
  976.     whelpush();
  977.     wmenubeg(9,22,14,38,0,LMAGENTA|_MAGENTA,LMAGENTA|_MAGENTA,pre_menu2);
  978.     for(i=0;i<4;i++) wmenuitem(i,0,compilers[i],*compilers[i],i,0,NULL,0,0);
  979.     wmenuend(0,M_VERT,15,1,LMAGENTA|_MAGENTA,LCYAN|_MAGENTA,0,BLUE|_LGREY);
  980.     if((subscr=wmenuget())==-1) if(_winfo.errno>W_ESCPRESS) error_exit(1);
  981.     kbput(0x4700);  /* [Home] */
  982.     if(subscr!=-1) {
  983.         kbputs(compilers[subscr]);
  984.         kbput(0x1615);  /* [Ctrl-U] */
  985.     }
  986.     kbput(0x1c0d);  /* [Enter] */
  987.     whelpop();
  988. }
  989.  
  990. /*---------------------------------------------------------------------------*/
  991.  
  992. /* this function demonstrates the string picker, the file */
  993. /* picker, and the in-place string selector functions.    */
  994.  
  995. static void pickdemo(void)
  996. {
  997.     register int *scrn;
  998.  
  999.     if((scrn=ssave())==NULL) error_exit(3);
  1000.     cclrscrn(LGREY|_BLUE);
  1001.     if(!wopen(4,11,14,68,3,LMAGENTA|_RED,LRED|_MAGENTA)) error_exit(1);
  1002.     add_shadow();
  1003.     wprintf("\033R\001\033C\003Select a month =>\033R\001\033C\003");
  1004.     whelpcat(H_STRPICK);
  1005.     you_selected(months[wpickstr(0,32,5,-1,0,LGREEN|_RED,LCYAN|_RED,RED|_LGREY
  1006.         ,months,0,pre_pick1)]);
  1007.     wprintf("\033R\003\033C\003Now, select a file.\033R\003\033C\003");
  1008.     whelpcat(H_FILEPICK);
  1009.     you_selected(wpickfile(10,9,20,66,0,LCYAN|_RED,LGREY|_RED,RED|_LGREY
  1010.         ,1,"*.*",add_shadow));
  1011.     wprintf("\033R\005\033C\003Select a printer port:\033R\005\033C\003");
  1012.     showcur();
  1013.     you_selected(prn_ports[wselstr(5,27,LMAGENTA|_MAGENTA,prn_ports,0)]);
  1014.     hidecur();
  1015.     wclose();
  1016.     srestore(scrn);
  1017.     move_bar_down();
  1018. }
  1019.  
  1020. /*---------------------------------------------------------------------------*/
  1021.  
  1022. static void popup_demo(void)
  1023. {
  1024.     whelpushc(H_PULLDOWN);
  1025.     wmenubeg(7,15,10,65,0,LRED,LCYAN|_BLUE,NULL);
  1026.     wmenuitem(0, 0,"Add",   'A',55,0,NULL,0,0);
  1027.     wmenuitxt(1,0,LGREEN|_BLUE,"Create a new record");
  1028.     wmenuitem(0, 8,"Delete",'D',56,0,NULL,0,0);
  1029.     wmenuitxt(1,0,LGREEN|_BLUE,"Delete an existing record");
  1030.     wmenuitem(0,19,"Print", 'P',57,0,NULL,0,0);
  1031.     wmenuitxt(1,0,LGREEN|_BLUE,"Print hardcopy of existing record");
  1032.     wmenuitem(0,28,"Show",  'S',58,0,NULL,0,0);
  1033.     wmenuitxt(1,0,LGREEN|_BLUE,"Display an existing record on screen");
  1034.     wmenuitem(0,36,"Update",'U',59,0,NULL,0,0);
  1035.     wmenuitxt(1,0,LGREEN|_BLUE,"Modify an existing record");
  1036.     wmenuitem(0,45,"Quit",  'Q',60,0,NULL,0,0);
  1037.     wmenuitxt(1,0,LGREEN|_BLUE,"Quit and return to pull-down menu");
  1038.     wmenuend(55,M_HORZ,0,0,LMAGENTA|_BLUE,WHITE|_BLUE,0,YELLOW|_LGREY);
  1039.     wmenuget();
  1040.     whelpopc();
  1041. }
  1042.  
  1043. /*---------------------------------------------------------------------------*/
  1044.  
  1045. static void pre_help(void)
  1046. {
  1047.     add_shadow();
  1048.     setonkey(0x2d00,confirm_quit,0);
  1049. }
  1050.  
  1051. /*---------------------------------------------------------------------------*/
  1052.  
  1053. /* this function is called during the setup of the main menu.  It is  */
  1054. /* called by wmenuget() right after the main menu's window is opened. */
  1055.  
  1056. static void pre_menu1(void)
  1057. {
  1058.     hidecur();
  1059.     add_shadow();
  1060. }
  1061.  
  1062. /*---------------------------------------------------------------------------*/
  1063.  
  1064. /* this function is called during the Data Entry demo when */
  1065. /* the user enters the Compiler field.  It is called by    */
  1066. /* wmenuget() after the compiler choice menu is opened.    */
  1067.  
  1068. static void pre_menu2(void)
  1069. {
  1070.     add_shadow();
  1071.     if(_mouse) msgotoxy(11,34);
  1072.     hidecur();
  1073. }
  1074.  
  1075. /*---------------------------------------------------------------------------*/
  1076.  
  1077. /* this function is called during the List Picking demo.  It is called */
  1078. /* by wpickstr() right after the string picker's window is opened.     */
  1079.  
  1080. static void pre_pick1(void)
  1081. {
  1082.     wmessage("┐ ┌",BT_BORD,4,LGREEN|_RED);
  1083.     add_shadow();
  1084. }
  1085.  
  1086. /*---------------------------------------------------------------------------*/
  1087.  
  1088. /* this function displays a pause message then pauses for a keypress */
  1089.  
  1090. static void press_a_key(int wrow)
  1091. {
  1092.     register int attr;
  1093.  
  1094.     attr=(BLINK|YELLOW)|((_winfo.active->wattr>>4)<<4);
  1095.     wcenters(wrow,attr,"Press a key");
  1096.     hidecur();
  1097.     if(waitkey()==ESC) confirm_quit();
  1098.     wcenters(wrow,attr,"           ");
  1099. }
  1100.  
  1101. /*---------------------------------------------------------------------------*/
  1102.  
  1103. static void pulldown_demo(void)
  1104. {
  1105.     int selection;
  1106.  
  1107.     whelpushc(H_PULLDOWN);
  1108.     if(!wopen(0,0,24,79,0,CYAN,CYAN)) error_exit(1);
  1109.     whline(1,0,78,0,CYAN);
  1110.     setkbloop(update_clock);
  1111.     wgotoxy(2,0);
  1112.     wtextattr(YELLOW);
  1113.     wputs("This is a sample editor interface to demonstrate how CXL's "
  1114.           "menuing functions\n");
  1115.     wputs("can be used to create a pull-down menu system.  Use the arr"
  1116.           "ow keys to move\n");
  1117.     wputs("selection bar around and use the [Esc] key to back up to th"
  1118.           "e previous menu.\n");
  1119.     wputs("Pressing [F1] will bring up context-sensitive help.  Select"
  1120.           " [Q]uit from any\n");
  1121.     wputs("menu to exit the pull-down demo.  Be sure to try some of th"
  1122.           "e menu options in\n");
  1123.     wputs("the pull-down menus.");
  1124.     if(_mouse)
  1125.         wputs("  Since you have a mouse, you can use it to "
  1126.               "move around\nand select options!");
  1127.  
  1128.     /* define menu structure */
  1129.     wmenubeg(1,1,1,78,5,CYAN,CYAN|_BLUE,NULL);
  1130.     wmenuitem(0,2,"File",'F',19,M_HASPD,NULL,0,H_FILE);
  1131.         wmenubeg(2,1,11,17,0,LGREY|_BLUE,_BLUE,NULL);
  1132.         wmenuitem(0,0,"Load"         ,'L',20,0,do_nothing,0,H_LOAD);
  1133.         wmenuitem(1,0,"Save"         ,'S',21,0,do_nothing,0,H_SAVE);
  1134.         wmenuitem(2,0,"Rename"       ,'R',22,0,do_nothing,0,H_RENAME);
  1135.         wmenuitem(3,0,"New"          ,'N',23,0,do_nothing,0,H_NEW);
  1136.         wmenuitem(4,0,"Directory  F5",'D',24,0,directory ,0x3f00,H_DIRECTORY);
  1137.         wmenuitem(5,0,"Execute    F6",'E',25,0,execute   ,0x4000,H_EXECUTE);
  1138.         wmenuitem(6,0,"OS Shell   F7",'O',26,M_CLOSB,os_shell,0x4100,H_OSSHELL);
  1139.         wmenuitem(7,0,"Quit"         ,'Q',27,M_CLALL,NULL,0,H_QUIT);
  1140.         wmenuiba(quit_window,quit_window);
  1141.         wmenuend(20,M_PD|M_SAVE,15,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1142.           ,YELLOW|_MAGENTA);
  1143.     wmenuitem(0,15,"Editing",'E',28,M_HASPD,NULL,0,H_EDITING);
  1144.         wmenubeg(2,14,10,28,0,LGREY|_BLUE,_BLUE,NULL);
  1145.         wmenuitem(0,0,"Cut"        ,'C',29,0      ,do_nothing  ,0,0);
  1146.         wmenuitem(1,0,"Paste"      ,'P',30,M_NOSEL,do_nothing  ,0,0);
  1147.         wmenuitem(2,0,"cOpy"       ,'O',31,M_NOSEL,do_nothing  ,0,0);
  1148.         wmenuitem(3,0,"block Begin",'B',32,0      ,toggle_block,0,0);
  1149.         wmenuitem(4,0,"block End"  ,'E',33,M_NOSEL,toggle_block,0,0);
  1150.         wmenuitem(5,0,"Insert line",'I',34,0      ,do_nothing  ,0,0);
  1151.         wmenuitem(6,0,"Delete line",'D',35,0      ,do_nothing  ,0,0);
  1152.         wmenuend(29,M_PD|M_SAVE,13,1,YELLOW|_BLUE,LCYAN|_BLUE,CYAN|_BLUE
  1153.             ,YELLOW|_MAGENTA);
  1154.     wmenuitem(0,31,"Defaults",'D',36,M_HASPD,NULL,0,0);
  1155.         wmenubeg(2,30,13,52,0,LGREY|_BLUE,_BLUE,setup_menu);
  1156.         wmenuitem(0,0,"Left margin       0",'L',37,0,do_nothing,0,0);
  1157.         wmenuitem(1,0,"Right margin     72",'R',38,0,r_margin  ,0,0);
  1158.         wmenuitem(2,0,"Tab width         4",'T',39,0,do_nothing,0,0);
  1159.         wmenuitem(4,0,"tab eXpansion   yes",'X',40,0,toggle_yn ,0,0);
  1160.         wmenuitem(5,0,"Insert mode     yes",'I',41,0,toggle_yn ,0,0);
  1161.         wmenuitem(6,0,"iNdent mode     yes",'N',42,0,toggle_yn ,0,0);
  1162.         wmenuitem(7,0,"Word wrap mode   no",'W',43,0,toggle_yn ,0,0);
  1163.         wmenuitem(9,0,"Save defaults"      ,'S',44,0,do_nothing,0,0);
  1164.         wmenuend(37,M_PD|M_SAVE,21,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1165.             ,YELLOW|_MAGENTA);
  1166.     wmenuitem(0,47,"Run"    ,'R',45,0      ,popup_demo,0,0);
  1167.     wmenuitem(0,59,"Options",'O',46,M_HASPD,NULL,0,0);
  1168.         wmenubeg(2,56,8,77,0,LGREY|_BLUE,_BLUE,NULL);
  1169.         wmenuitem(0,0,"screen siZe     43",'Z',47,0,do_nothing,0,0);
  1170.         wmenuitem(1,0,"Backup files   yes",'B',48,0,toggle_yn ,0,0);
  1171.         wmenuitem(2,0,"bOxed display   no",'O',49,0,toggle_yn ,0,0);
  1172.         wmenuitem(3,0,"Load options"      ,'L',50,0,do_nothing,0,0);
  1173.         wmenuitem(4,0,"Save options"      ,'S',51,0,do_nothing,0,0);
  1174.         wmenuend(47,M_PD|M_SAVE,20,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1175.             ,YELLOW|_MAGENTA);
  1176.     wmenuitem(0,73,"Quit",'Q',52,M_HASPD,NULL,0,0);
  1177.     wmenuiba(quit_window,quit_window);
  1178.         wmenubeg(2,60,7,78,0,LGREY|_BLUE,_BLUE,disp_sure_msg);
  1179.         wmenuitem(2,0,"No" ,'N',53,M_CLOSE,NULL,0,0);
  1180.         wmenuitem(3,0,"Yes",'Y',54,M_CLALL,NULL,0,0);
  1181.         wmenuend(53,M_PD,17,7,YELLOW|_BLUE,LCYAN|_BLUE,WHITE|_BLUE
  1182.             ,YELLOW|_MAGENTA);
  1183.     wmenuend(19,M_HORZ,0,0,YELLOW|_BLUE,LCYAN|_BLUE,0,YELLOW|_MAGENTA);
  1184.  
  1185.     /* process the menu */
  1186.     selection=wmenuget();
  1187.     if(selection==-1&&_winfo.errno>W_ESCPRESS) error_exit(1);
  1188.     wclose();
  1189.     setkbloop(NULL);
  1190.     whelpopc();
  1191. }
  1192.  
  1193. /*---------------------------------------------------------------------------*/
  1194.  
  1195. /* this function is called by the pull-down menu demo anytime */
  1196. /* the  selection bar moves on or off the [Q]uit menu items.  */
  1197.  
  1198. static void quit_window(void)
  1199. {
  1200.     static WINDOW handle=0;
  1201.  
  1202.     if(handle) {
  1203.         wactiv(handle);
  1204.         wclose();
  1205.         handle=0;
  1206.     }
  1207.     else {
  1208.         handle=wopen(14,41,17,70,0,YELLOW|_RED,WHITE|_RED);
  1209.         wputs(" Quit takes you back to the\n demo program's main menu.");
  1210.     }
  1211. }
  1212.  
  1213. /*---------------------------------------------------------------------------*/
  1214.  
  1215. /* this function handles the setting of the [R]ight   */
  1216. /* margin setting under the [D]efault pull-down menu. */
  1217.  
  1218. static void r_margin(void)
  1219. {
  1220.     winpbeg(WHITE|_CYAN,WHITE|_CYAN);
  1221.     winpdef(1,17,wmenuicurr()->str+16,"%%#",'9',1,NULL,0);
  1222.     winpread();
  1223.     hidecur();
  1224.     wmenuicurr()->redisp=YES;
  1225. }
  1226.  
  1227. /*---------------------------------------------------------------------------*/
  1228.  
  1229. static void resize_demo(void)
  1230. {
  1231.     whelpcat(H_RESIZE);
  1232.     wtextattr(LGREEN|_GREEN);
  1233.     wputs("\n\n\n  The wsize() function"
  1234.               "\n  allows you to resize"
  1235.               "\n  the active window.");
  1236.     press_a_key(10);
  1237.     size_window(19,60);
  1238.     size_window(19,75);
  1239.     size_window(24,75);
  1240.     size_window(24,60);
  1241.     size_window(24,45);
  1242.     size_window(19,45);
  1243. }
  1244.  
  1245. /*---------------------------------------------------------------------------*/
  1246.  
  1247. static void restore_cursor(void)
  1248. {
  1249.     wtextattr(WHITE|_MAGENTA);
  1250.     showcur();
  1251. }
  1252.  
  1253. /*---------------------------------------------------------------------------*/
  1254.  
  1255. static void scroll_demo(void)
  1256. {
  1257.     register int i,j;
  1258.  
  1259.     if((w[0]=wopen(1,1,11,41,2,LMAGENTA|_RED,LCYAN|_RED))==0) error_exit(1);
  1260.     whelpcat(H_SCROLL);
  1261.     wprintf("\n  CXL's window TTY output functions"
  1262.             "\n  such as wputs() and wprintf() allow"
  1263.             "\n  scrolling and ANSI-like Escape code"
  1264.             "\n  sequences from inside of windows.");
  1265.     press_a_key(6);
  1266.     wgotoxy(8,0);
  1267.     for(i=0;i<10;i++) {
  1268.         for(j=DGREY;j<=WHITE;j++) {
  1269.             wprintf("\033F%cCXL   ",j);
  1270.             delay_(1);
  1271.         }
  1272.     }
  1273. }
  1274.  
  1275. /*---------------------------------------------------------------------------*/
  1276.  
  1277. /* this function sets up the [D]efaults menu for the pull-down demo */
  1278.  
  1279. static void setup_menu(void)
  1280. {
  1281.     whline(3,0,21,0,LGREY|_BLUE);
  1282.     whline(8,0,21,0,LGREY|_BLUE);
  1283. }
  1284.  
  1285. /*---------------------------------------------------------------------------*/
  1286.  
  1287. static void short_delay(void)
  1288. {
  1289.     delay_(SHORT_DELAY);
  1290. }
  1291.  
  1292. /*---------------------------------------------------------------------------*/
  1293.  
  1294. static void size_window(int nerow,int necol)
  1295. {
  1296.     wsize(nerow,necol);
  1297.     short_delay();
  1298. }
  1299.  
  1300. /*---------------------------------------------------------------------------*/
  1301.  
  1302. static void text_line_demo(void)
  1303. {
  1304.     if((w[3]=wopen(10,3,23,41,3,YELLOW|_BLUE,LMAGENTA|_BLUE))==0)
  1305.         error_exit(1);
  1306.     whelpcat(H_TEXTLINE);
  1307.     wputs("\n  The whline() & wvline() functions"
  1308.           "\n  are used for drawing \"smart\" text"
  1309.           "\n  lines which will even make their "
  1310.           "\n  own corners and intersections!   ");
  1311.     press_a_key(6);
  1312.     horz_line(6,6,24,LCYAN|_BLUE);
  1313.     vert_line(6,6,4,LCYAN|_BLUE);
  1314.     horz_line(10,6,24,LCYAN|_BLUE);
  1315.     vert_line(6,30,5,LRED|_BLUE);
  1316.     vert_line(6,18,5,LRED|_BLUE);
  1317.     horz_line(7,6,25,LRED|_BLUE);
  1318.     horz_line(9,6,25,LGREEN|_BLUE);
  1319.     vert_line(6,11,5,LGREEN|_BLUE);
  1320.     vert_line(6,23,5,LGREEN|_BLUE);
  1321.     horz_line(8,6,25,LMAGENTA|_BLUE);
  1322. }
  1323.  
  1324. /*---------------------------------------------------------------------------*/
  1325.  
  1326. static void title_demo(void)
  1327. {
  1328.     if((w[2]=wopen(5,20,19,45,3,LCYAN|_GREEN,WHITE|_GREEN))==0) error_exit(1);
  1329.     whelpcat(H_WINTITLE);
  1330.     wputs("\n  The wtitle() function"
  1331.           "\n  allows you to give a"
  1332.           "\n  window a title.");
  1333.     press_a_key(5);
  1334.     display_title(TLEFT);
  1335.     display_title(TRIGHT);
  1336.     display_title(TCENTER);
  1337. }
  1338.  
  1339. /*---------------------------------------------------------------------------*/
  1340.  
  1341. /* this function toggles "block marking" on and off */
  1342. /* in the sample editor of the pulldown menu demo   */
  1343.  
  1344. static void toggle_block(void)
  1345. {
  1346.     static int block=OFF;
  1347.  
  1348.     if(block) {
  1349.         block=OFF;
  1350.         wmenuienab(32);
  1351.         wmenuidsab(33);
  1352.         wmenuinext(32);
  1353.     }
  1354.     else {
  1355.         block=ON;
  1356.         wmenuidsab(32);
  1357.         wmenuienab(33);
  1358.         wmenuinext(33);
  1359.     }
  1360.  
  1361.     if(wopen(11,30,15,49,0,LRED|_MAGENTA,WHITE|_MAGENTA)) {
  1362.         wprintf("\n Block is now o%s",block?"n":"ff");
  1363.         delay_(10);
  1364.         wclose();
  1365.     }
  1366. }
  1367.  
  1368. /*---------------------------------------------------------------------------*/
  1369.  
  1370. /* This function toggles the yes/no status of some pull-down menu items.   */
  1371. /* This is to show you can modify the menu item's string and redisplay it. */
  1372. /* This is done by getting the address of the current menu item's struct,  */
  1373. /* then modifying the string pointed to by the str element.  The redisp    */
  1374. /* flag is set so that when you return to the menu, the screen will be     */
  1375. /* automatically updated.                                                  */
  1376.  
  1377. static void toggle_yn(void)
  1378. {
  1379.     struct _item_t *citem;
  1380.     char *str,*yn;
  1381.  
  1382.     citem=wmenuicurr();
  1383.     str=citem->str;
  1384.     yn=str+strlen(str)-3;
  1385.     strcpy(yn,strcmp(yn,"yes")?"yes":" no");
  1386.     citem->redisp=1;
  1387. }
  1388.  
  1389. /*---------------------------------------------------------------------------*/
  1390.  
  1391. /* this function updates the on-screen clock in the pull-down demo. */
  1392.  
  1393. static void update_clock(void)
  1394. {
  1395.     prints(0,70,LGREEN,systime(1));
  1396. }
  1397.  
  1398. /*---------------------------------------------------------------------------*/
  1399.  
  1400. static void vert_line(int wrow,int wcol,int count,int attr)
  1401. {
  1402.     wvline(wrow,wcol,count,3,attr);
  1403.     short_delay();
  1404. }
  1405.  
  1406. /*---------------------------------------------------------------------------*/
  1407.  
  1408. /* this function is used by the List Picking demo to display a selected    */
  1409. /* string, or display an error message if an error occurred.  It also      */
  1410. /* prompts the user for a keypress 2 lines below the string/error message. */
  1411.  
  1412. static void you_selected(char *str)
  1413. {
  1414.     int wrow,wcol;
  1415.  
  1416.     if(_winfo.errno)
  1417.         wprintf("\033EL%s",werrmsg());
  1418.     else
  1419.         wprintf("\033ELYou selected:  \033F\005%s\033F\004",str);
  1420.     whelpcat(H_LISTPICK);
  1421.     wreadcur(&wrow,&wcol);
  1422.     press_a_key(wrow+2);
  1423. }
  1424.  
  1425. /*---------------------------------------------------------------------------*/
  1426.  
  1427. static void windemo(void)
  1428. {
  1429.     int *scrn;
  1430.  
  1431.     if((scrn=ssave())==NULL) error_exit(3);
  1432.     cclrscrn(LGREY|_BLACK);
  1433.     scroll_demo();
  1434.     chg_attr_demo();
  1435.     chg_bord_demo();
  1436.     title_demo();
  1437.     resize_demo();
  1438.     text_line_demo();
  1439.     move_demo();
  1440.     hide_demo();
  1441.     activate_demo();
  1442.     copy_demo();
  1443.     close_windows();
  1444.     srestore(scrn);
  1445.     clearkeys();
  1446.     move_bar_down();
  1447. }
  1448.